using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;

namespace RadioTimer.Services
{
    /// <summary>
    /// Toast消息服务类
    /// 提供跨平台的Toast和Snackbar消息显示功能
    /// </summary>
    public static class ToastService
    {
        /// <summary>
        /// 显示Toast消息
        /// </summary>
        /// <param name="message">要显示的消息</param>
        /// <param name="duration">显示持续时间</param>
        public static async Task ShowToastAsync(string message, ToastDuration duration = ToastDuration.Short)
        {
            try
            {
                var toast = Toast.Make(message, duration);
                await toast.Show();
            }
            catch (Exception ex)
            {
                // 如果Toast失败，回退到Debug输出
                Services.DebugLogger.WriteError($"显示Toast消息失败: {ex.Message}");
            }
        }
        
        /// <summary>
        /// 显示Snackbar消息
        /// </summary>
        /// <param name="message">要显示的消息</param>
        /// <param name="actionButtonText">操作按钮文本，默认为null</param>
        /// <param name="duration">显示持续时间</param>
        public static async Task ShowSnackbarAsync(string message, string? actionButtonText = null, TimeSpan? duration = null)
        {
            try
            {
                var snackbar = string.IsNullOrEmpty(actionButtonText) 
                    ? Snackbar.Make(message, duration: duration)
                    : Snackbar.Make(message, () => { }, actionButtonText, duration: duration);
                    
                await snackbar.Show();
            }
            catch (Exception ex)
            {
                // 如果Snackbar失败，回退到Debug输出
                Services.DebugLogger.WriteError($"显示Snackbar消息失败: {ex.Message}");
            }
        }
    }
}